package com.example.wanandroid.core.utils;


import com.example.wanandroid.core.http.api.Apis;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpUtil {

    private static volatile Retrofit retrofit;
    private static volatile Apis api;

    public static Retrofit getRetrofit(){
        if(retrofit==null){
            synchronized(Retrofit.class){
                if(retrofit==null){
                    retrofit = new Retrofit.Builder()
                            .baseUrl(Apis.HOST) // 设置网络请求baseUrl
                            .addConverterFactory(GsonConverterFactory.create()) //设置使用Gson解析
                            .build();
                }
            }
        }
        return retrofit;
    }

    public static Apis getApi(){
        if(api==null){
            synchronized(Apis.class){
                if(api==null){
                    api = getRetrofit().create(Apis.class);
                }
            }
        }
        return api;
    }
}
